package com.woniuxy.service03;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author 佘赛飞
 * @create 2021 -11 -04 5:30 PM
 */
public class SomeServiceTest {
//    @Test
//    public void test01(){
//        //耦合
////        SomeService someService = new SomeServiceImpl();
//        SomeService someService = new SomeServiceImpl2();
//        someService.doSome();
//    }

    @Test
    public void test02(){
        String path= "com/woniuxy/service03/applicationContext.xml";
        //相对路径 类路径 src根目录
        ApplicationContext ac=
                new ClassPathXmlApplicationContext(path);
        SomeService someService = (SomeService)ac.getBean("someService");
        someService.doSome();
    }

    @Test
    public void test03(){
        String path= "com/woniuxy/service02/applicationContext.xml";
        //相对路径 类路径 src根目录
        ApplicationContext ac=
                new ClassPathXmlApplicationContext(path);
        //工厂接口和实现类没有耦合
        SomeServiceFactory someServiceFactory = (SomeServiceFactory)ac.getBean("factory");
        //工厂调用其他方法，切换产品，工厂和产品之间有耦合
        //将工厂bean当成普通bean，用了框架，还是有耦合
        SomeService someService = someServiceFactory.getSomeService();
        someService.doSome();
    }
}
